package Day8_07_31;

import java.util.ArrayList;
import java.util.Scanner;

public class StudentManger {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		ArrayList<Student> list = new ArrayList<Student>();
		while (true) {
			System.out.println("请输入学生的ID:");
			int id = scanner.nextInt();
			System.out.println("请输入学生的名字：");
			String name = scanner.next();
			System.out.println("请输入学生的年龄：");
			int age = scanner.nextInt();
			System.out.println("请输入学生的班级：");
			String className = scanner.next();
			Student student = new Student(id, name, age, className);
			list.add(student);
			System.out.println("是否结束？结束，输入0");
			int end = scanner.nextInt();
			if (end == 0) {
				break;
			}
		}
		System.out.println("**************");
		System.out.println("下面为输入的学生信息：");
		System.out.println("**************");
		for (Student student : list) {
			System.out.println(student);
		}

		while (true) {
			System.out.println("----------------------");
			System.out.println("根据id查找输入：1");
			System.out.println("根据名字查找输入：2");
			System.out.println("根据年龄查找输入：3");
			System.out.println("根据班级查找输入：4");
			System.out.println("退出程序：0");
			System.out.println("----------------------");
			int type = scanner.nextInt();
			if (type == 0) {
				System.out.println("退出程序");
				break;
			}
			switch (type) {
			case 1:
				System.out.println("根据id搜索");
				int searchId = scanner.nextInt();
				boolean isSearchByIdFound = false;
				for (Student student : list) {
					if (student.id == searchId) {
						isSearchByIdFound = true;
						System.out.println("有id为：“" + student.getId() + "”的学生，信息如下：");
						System.out.println(student);
					}
				}
				if (isSearchByIdFound=false) {
					System.out.println("没有这个id的学生");
				}
				break;
			case 2:
				System.out.println("根据名字搜索");
				String searchName = scanner.next();
				boolean isSearchByNameFound = false;
				for (Student student : list) {
					if (student.name.equals(searchName)) {
						isSearchByNameFound = true;
						System.out.println("有名字为：“" + student.getName() + "”的学生，信息如下：");
						System.out.println(student);
					}	
				}
				if (isSearchByNameFound = false) {
					System.out.println("没有这个名字的学生");
				}
				break;
			case 3:
				System.out.println("根据年龄搜索");
				int searchAge = scanner.nextInt();
				boolean isSearchByAgeFound = false;
				for (Student student : list) {
					if (student.age== searchAge) {
						isSearchByAgeFound = true;
						System.out.println("有年龄为：“" + student.getAge() + "”的学生，信息如下：");
						System.out.println(student);
					}
				}
				if (isSearchByAgeFound=false) {
					System.out.println("没有这个年龄的学生");
				}
				break;
			case 4:
				System.out.println("根据班级搜索");
				String searchClassName = scanner.next();
				boolean isSearchByClassNameFound = false;
				for (Student student : list) {
					if (student.className.equals(searchClassName)) {
						isSearchByClassNameFound = true;
						System.out.println("有班级为：“" + student.getClassName() + "”的学生，信息如下：");
						System.out.println(student);
					}
				}
				if (isSearchByClassNameFound=false) {
					System.out.println("没有这个班级的学生");
				}
				break;
			default:
				break;
			}
		}
	}
}